package com.mimiwang.common.utils;

import java.util.HashMap;

/**
 * @program: Forum
 * @description:验证token并获取当前userId实现类
 * @author: 2727302640@qq.com
 * @create: 2022-03-27 20:12
 */
public class TokenUtil {
    public static String verify(String token) throws NullPointerException{
        try{
            JwtUtil.tokenVerify(token);
        }catch (Exception e){
            throw  new NullPointerException("token验证失败");
        }
        return JwtUtil.getPayloadFromToken(token).get("id").asString();
    }
    public static String generateToken(long id){

        return JwtUtil.getToken(new HashMap<String, String>() {{
            put("id",String.valueOf(id));
        }});
    }
}